﻿using System;
using System.Collections.Generic;
using Medianamik.Core.Reports;

namespace Medianamik.Core.Urls
{
    public class UrlDictionaryReport : IEquatable<UrlDictionaryReport>, IReport
    {
        public UrlDictionaryReport()
        {
            DuplicatedEntries = new List<IUrlDictionaryEntry>();
            RemovedEntries = new List<IUrlDictionaryEntry>();
            AddedEntries = new List<IUrlDictionaryEntry>();
        }

        public ReportAction ReportedReportAction { get; set; }
        public int NumberTotalOfEntries { get; set; }
        public int NumberOfDistinctEntries { get; set; }
        public List<IUrlDictionaryEntry> DuplicatedEntries { get; set; }

        public Guid UpdatedNodeId { get; set; }
        public int NumberTotalOfEntriesBeforeRemove { get; set; }
        public int NumberOfRemovedEntries { get; set; }
        public int NumberOfAddedEntries { get; set; }
        public List<IUrlDictionaryEntry> RemovedEntries { get; set; }
        public List<IUrlDictionaryEntry> AddedEntries { get; set; }

        #region IEquatable

        public bool Equals(UrlDictionaryReport other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            return other.NumberTotalOfEntries == NumberTotalOfEntries &&
                   other.NumberOfDistinctEntries == NumberOfDistinctEntries &&
                   DuplicatedEntries.TrueForAll(other.DuplicatedEntries.Contains) &&
                   other.DuplicatedEntries.TrueForAll(DuplicatedEntries.Contains);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(UrlDictionaryReport)) return false;
            return Equals((UrlDictionaryReport)obj);
        }

        public static bool operator ==(UrlDictionaryReport left, UrlDictionaryReport right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(UrlDictionaryReport left, UrlDictionaryReport right)
        {
            return !Equals(left, right);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = NumberTotalOfEntries;
                result = (result * 397) ^ NumberOfDistinctEntries;
                result = (result * 397) ^ (DuplicatedEntries != null ? DuplicatedEntries.GetHashCode() : 0);
                return result;
            }
        }

        #endregion
    }

    public enum ReportAction
    {
        Initialized,
        Reload,
        UpdateNodeEntries,
        Failure
    }
}
